const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
module.exports = merge(common, {
  plugins: [
    new CleanWebpackPlugin(),
    new UglifyJsPlugin({
      parallel: true
    }),
    new OptimizeCSSPlugin({
      cssProcessorOptions: { safe: true }
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: 'public'
        }
      ]
    }),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new HtmlWebpackPlugin({
      title: 'test',
      template: 'public/index.html',
      templateParameters: {
        BASE_URL: 'public'
      },
      inject: true
    })
  ],
  optimization: {
    splitChunks: {
      chunks: 'all'
    },
    concatenateModules: true,
    usedExports: true,
    minimize: true
  }
})
